<?php
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class M_penyakit extends CI_Model
{
    
    public function __construct() {
        parent::__construct();
    }
    
   function ritl() {
        $sql = 'SELECT *,
            (SELECT count(id) FROM penyakit penyakit1 
                WHERE jk = "L" AND penyakit1.icd10 = penyakit.icd10 AND penyakit1.kode = 2) as laki, 
            (SELECT count(id) FROM penyakit penyakit2 
                WHERE jk = "P" AND penyakit2.icd10 = penyakit.icd10 AND penyakit2.kode = 2) as perempuan,
            (SELECT count(id) FROM penyakit penyakit3 
                WHERE penyakit3.id_status_keluar <> 2 AND penyakit3.icd10 = penyakit.icd10 AND kode = 2) as keluar,
            (SELECT count(id) FROM penyakit penyakit4 
                WHERE penyakit4.id_status_keluar = 2 AND penyakit4.icd10 = penyakit.icd10 AND kode = 2) as meninggal
            FROM penyakit WHERE penyakit.kode = 2 GROUP BY icd10';
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $result = $query->result_array();
            $query->free_result();
        } else {
            $result = array();
        }
        return $result;
    }

    function rjtl() {
        $sql = 'SELECT *,
            (SELECT count(id) FROM penyakit penyakit1 
                WHERE jk = "L" AND penyakit1.icd10 = penyakit.icd10 AND penyakit1.kode = 1) as laki, 
            (SELECT count(id) FROM penyakit penyakit2 
                WHERE jk = "P" AND penyakit2.icd10 = penyakit.icd10 AND penyakit2.kode = 1) as perempuan,
            (SELECT count(id) FROM penyakit penyakit3 
                WHERE penyakit3.icd10 = penyakit.icd10 AND penyakit3.kode = 1) as kunjungan
            FROM penyakit WHERE penyakit.kode = 1 GROUP BY icd10';
        $query = $this->db->query($sql);
        if ($query->num_rows() > 0) {
            $result = $query->result_array();
            $query->free_result();
        } else {
            $result = array();
        }
        return $result;
    }
}
